﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using ParieurPro.DAL.DatabaseModel;

namespace ParieurPro.DAL
{
    /// <summary>
    /// Classe de gestion des championnats (Ligue 1, Ligue 2, ...)
    /// Un championnat est constitué d'un nom, d'un logo (bitmap) et d'un identifiant unique
    /// </summary>
    [DataContractAttribute(IsReference = true)]
    [Serializable()]
    public class ChampionshipObject
    {
        #region Attributes
        private int _championshipId;
        private string _name;
        private byte[] _image;
        #endregion

        #region Properties

        /// <summary>
        /// Identifiant unique du championnat
        /// </summary>
        [Key()]
        [DataMemberAttribute()]
        public int ChampionshipId
        {
            get { return _championshipId; }
            set { _championshipId = value; }
        }
        
        /// <summary>
        /// Nom du championnat
        /// </summary>
        [DataMemberAttribute()]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Logo du championnat
        /// </summary>
        [DataMemberAttribute()]
        public byte[] Image
        {
            get { return _image; }
            set { _image = value; }
        }
        #endregion

        #region Data access
        /// <summary>
        /// Copie l'objet représentant la table "Championships" de la base de données
        /// en objet "ChampionshipObject" 
        /// </summary>
        /// <param name="dataToCopy">Objet à copier</param>
        /// <returns>Objet copié</returns>
        /// <exception cref="ArgumentException">dataToCopy vaut null</exception>
        public static ChampionshipObject CopyFromDatabaseObject(Championships dataToCopy)
        {
            if (dataToCopy == null)
            {
                throw new ArgumentException("ChampionshipObject.CopyFromDatabaseObject - dataToCopy can not be null");
            }
            ChampionshipObject championship = new ChampionshipObject();
            championship.ChampionshipId = dataToCopy.ChampionshipId;
            championship.Name = dataToCopy.Name;
            championship.Image = dataToCopy.Icon;
            return championship;
        }
        #endregion

    }
}